package com.wanghua.mall.order.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单结算（确认）页面数据
 *
 * @author wanghua
 * @create 2021-09-08 12:33
 */
@Data
public class OrderConfirmVo {

    //用户收货地址列表
    private List<UserReceiveAddressVo> userReceiveAddressVoList;

    //所有选中的购物项
    private List<OrderItemVo> orderItemVoList;

    //发票记录

    //用户积分信息（优惠卷）
    private Integer integration;

    //防重令牌
    private String orderToken;

    //某件商品是否有库存
    Map<Long, Boolean> stock;

    //订单总额
//    private BigDecimal total;

    //应付价格
//    private BigDecimal payPrice;

    //订单总额
    public BigDecimal getTotal() {
        BigDecimal res = new BigDecimal(0);
        if (orderItemVoList != null && orderItemVoList.size() > 0) {
            for (OrderItemVo orderItemVo : orderItemVoList) {
                res = res.add(orderItemVo.getPrice().multiply(new BigDecimal(orderItemVo.getCount())));
            }
        }
        return res;
    }

    //应付价格
    public BigDecimal getPayPrice() {
        return getTotal();
    }

    //商品数量
    public Integer getCount() {
        int res = 0;
        if (orderItemVoList != null && orderItemVoList.size() > 0) {
            for (OrderItemVo orderItemVo : orderItemVoList) {
                res += orderItemVo.getCount();
            }
        }
        return res;
    }
}
